#!/bin/bash

## 获取当前脚本名
script_name=$0

## 去除-前的字符和.后的字符
## colcon_build-pkg01_helloworld_cpp.sh -> pkg01_helloworld_cpp
script_name_start=$(echo "${script_name}" | awk -F"-" '{print $2}'|awk -F"." '{print $1}')

## 截取名字中，可执行文件的名字
### pkg01_helloworld_cpp -> helloworld
exec_name=$(echo "${script_name_start}" | awk -F"_" '{print $2}'|awk -F"_" '{print $1}')

#echo "cript_name_start=${cript_name_start}"
#echo "exec_name=${exec_name}"
#exit

echo ""
echo "[ Info ] colcon build ${script_name_start}"
echo ""
colcon build --packages-select ${script_name_start}
echo ""
echo "[ Info ] source ./install/setup.bash"
source ./install/setup.bash
echo ""
echo "[ Info ] sleep 1"
sleep 1
echo ""
echo "[ Info ] ros2 run ${script_name_start} ${exec_name}"
ros2 run ${script_name_start} ${exec_name}
echo ""
